package cc.wsyw126.java.nowcoder.sword_offer;

import cc.wsyw126.java.lintCode.swap_two_nodes_in_linked_list.ListNode;

/**
 * Created by dp on 17/3/28.
 */
public class ReverseList {
    public ListNode ReverseList(ListNode head) {
        if (head == null) return null;
        if (head.next ==null) return head;

        ListNode temp = head;
        ListNode in = temp.next;
        temp.next = null;
        while (in!=null) {
            ListNode next1 = in.next;
            in.next=temp;
            temp = in;
            in = next1;
        }
        return temp;
    }

    public static void main(String[] args) {
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3 = new ListNode(3);

        listNode1.next = listNode2;
        listNode2.next = listNode3;

        ReverseList reverseList = new ReverseList();
        ListNode listNode = reverseList.ReverseList(listNode1);
        while (listNode != null) {
            System.out.println(listNode.val);
            listNode = listNode.next;
        }

    }
}
